const { createProxyMiddleware } = require('http-proxy-middleware')

// According to:
// https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually
module.exports = function (app) {
  app.use(
    '/chouti-img',
    createProxyMiddleware({
      target: 'https://img3.chouti.com/',
      changeOrigin: true,
      pathRewrite: {
        '^/chouti-img': '/',
      },
      headers: {
        Referer: 'https://dig.chouti.com/',
      },
    })
  )


  // 炉石传说 https://hs.fbigame.com/
  app.use(
    '/hs-api',
    createProxyMiddleware({
      target: 'https://hs.fbigame.com/ajax.php',
      changeOrigin: true,
      pathRewrite: {
        '^/hs-api': '/ajax.php',
      },
      headers: {
        Referer: 'https://hs.fbigame.com/',
      },
    })
  )

  app.use(
    '/hs-img',
    createProxyMiddleware({
      target: 'https://images.fbigames.com',
      changeOrigin: true,
      pathRewrite: {
        '^/hs-img': '/',
      },
      headers: {
        Referer: 'https://hs.fbigame.com/',
      },
    })
  )
}
